/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.devmng.web;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.devmng.entity.TaskDelayApplyLog;
import com.thinkgem.jeesite.modules.devmng.service.TaskDelayApplyLogService;
import com.thinkgem.jeesite.modules.devmng.service.TaskMainService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 任务延迟申请记录Controller
 *
 * @author yfy
 * @version 2018-02-03
 */
@Controller
@RequestMapping(value = "${adminPath}/devmng/taskDelayApplyLog")
public class TaskDelayApplyLogController extends BaseController {

    @Autowired
    private TaskDelayApplyLogService taskDelayApplyLogService;

    @Autowired
    private TaskMainService taskMainService;

    @ModelAttribute
    public TaskDelayApplyLog get(@RequestParam(required = false) String id) {
        TaskDelayApplyLog entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = taskDelayApplyLogService.get(id);
        }
        if (entity == null) {
            entity = new TaskDelayApplyLog();
        }
        return entity;
    }

    @RequiresPermissions("devmng:taskDelayApplyLog:view")
    @RequestMapping(value = {"list", ""})
    public String list(TaskDelayApplyLog taskDelayApplyLog, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<TaskDelayApplyLog> page = taskDelayApplyLogService.findPage(new Page<TaskDelayApplyLog>(request, response), taskDelayApplyLog);
        model.addAttribute("page", page);
        return "modules/devmng/taskDelayApplyLogList";
    }

    @RequiresPermissions("devmng:taskDelayApplyLog:view")
    @RequestMapping(value = "form")
    public String form(TaskDelayApplyLog taskDelayApplyLog, Model model) {
        model.addAttribute("taskDelayApplyLog", taskDelayApplyLog);
        return "modules/devmng/taskDelayApplyLogForm";
    }

    @RequiresPermissions("devmng:taskDelayApplyLog:edit")
    @RequestMapping(value = "save")
    public String save(TaskDelayApplyLog taskDelayApplyLog, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, taskDelayApplyLog)) {
            return form(taskDelayApplyLog, model);
        }
        taskDelayApplyLogService.save(taskDelayApplyLog);
        addMessage(redirectAttributes, "保存任务延迟申请记录成功");
        return "redirect:" + Global.getAdminPath() + "/devmng/taskDelayApplyLog/?repage";
    }

    @RequiresPermissions("devmng:taskDelayApplyLog:edit")
    @RequestMapping(value = "delete")
    public String delete(TaskDelayApplyLog taskDelayApplyLog, RedirectAttributes redirectAttributes) {
        taskDelayApplyLogService.delete(taskDelayApplyLog);
        addMessage(redirectAttributes, "删除任务延迟申请记录成功");
        return "redirect:" + Global.getAdminPath() + "/devmng/taskDelayApplyLog/?repage";
    }

    @RequiresUser
    @RequestMapping(value = "pass")
    public String pass(TaskDelayApplyLog taskDelayApplyLog, RedirectAttributes redirectAttributes) {
        taskMainService.pass(taskDelayApplyLog.getId());
        return "redirect:" + Global.getAdminPath() + "/devmng/taskDelayApplyLog/?repage";
    }

    @RequiresUser
    @RequestMapping(value = "reject")
    public String reject(TaskDelayApplyLog taskDelayApplyLog, RedirectAttributes redirectAttributes) {
        taskMainService.reject(taskDelayApplyLog.getId());
        return "redirect:" + Global.getAdminPath() + "/devmng/taskDelayApplyLog/?repage";
    }


}